import subprocess
import argparse
import pathlib 
import sys
# export PYTHONPATH="/data/work/jmash/python/jmash-cmd"
import jmash_cmd.pnpm
import jmash_cmd.docker
import jmash_cmd.k8s
        
if __name__ == "__main__":
    parser = argparse.ArgumentParser(description="K8S应用程序管理脚本")
    parser.add_argument("action", choices=["package","publish","deploy", "restart", "delete", "scale"], help="要执行的操作")
    parser.add_argument("arch", choices=["amd64", "arm64"], help="目标架构")
    parser.add_argument("--version", default="1.0.0",  help="版本")
    parser.add_argument("--namespace", default="jmash", help="命名空间")   
    parser.add_argument("--name", default="sample", help="应用程序名称")
     
    parser.add_argument("--replicas", default="2", help="副本数量")
            
    args = parser.parse_args()
    # 路径
    # args.path= pathlib.Path.cwd()
    mirror="docker.dev.crenjoy.com"
    
    print(args);
    if args.action == "all":
        jmash_cmd.pnpm.pnpm_main(args.namespace,args.name)
        jmash_cmd.docker.docker_vue_build_push(args.namespace,args.name,args.arch, args.version,mirror)
        jmash_cmd.k8s.k8s_vue_deploy(args.name,args.arch,args.version,mirror)
    elif args.action == "package":
        jmash_cmd.pnpm.pnpm_main(args.namespace,args.name)
    elif args.action == "publish":
        jmash_cmd.docker.docker_vue_build_push(args.namespace,args.name,args.arch, args.version,mirror)
    elif args.action == "deploy":
        jmash_cmd.k8s.k8s_vue_restart(args.namespace,args.name, args.arch) 
        jmash_cmd.k8s.k8s_vue_deploy(args.name,args.arch,args.version,mirror)
    elif args.action == "restart":
        jmash_cmd.k8s.k8s_vue_restart(args.namespace,args.name, args.arch)  
    elif args.action == "delete":
        jmash_cmd.k8s.k8s_vue_delete(args.name, args.arch)
    elif args.action == "scale":
        jmash_cmd.k8s.k8s_vue_scale(args.namespace,args.name,  args.replicas)
   
   
